package activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import com.jakewharton.rxbinding.view.RxView;
import com.jzxiang.pickerview.TimePickerDialog;
import com.jzxiang.pickerview.listener.OnDateSetListener;

import net.ck.hzq.R;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

import Bean.JiFenRecordBean;
import Bean.SiteAddressBean;
import base.BaseAct;
import base.BaseBiz;
import base.SuperBaseAdapter;
import butterknife.BindView;
import cn.finalteam.loadingviewfinal.OnDefaultRefreshListener;
import cn.finalteam.loadingviewfinal.PtrClassicFrameLayout;
import cn.finalteam.loadingviewfinal.PtrFrameLayout;
import cn.finalteam.loadingviewfinal.RecyclerViewFinal;
import event.DefaultAddressEvent;
import event.NetErrorEvent;
import event.SiteAddressEvent;
import ui.activity.login.biz.LoginBiz;
import ui.adapter.JiFenLiuZhuanRecordAdapter;
import ui.adapter.SiteAddressAdapter;
import util.AlertUtils;
import util.SysUtils;


/**
 * 提现列表
 * Created by chenjian on 2017/8/4.
 */

public class SelectAddressAct extends BaseAct{

    @BindView(R.id.pull_refresh_rv)
    RecyclerViewFinal rv;
    @BindView(R.id.pull_refresh_ptr)
    PtrClassicFrameLayout ptr;
    private SharedPreferences sp;

    SiteAddressAdapter adp;
    String timeStr = "";
    List<String> address= new ArrayList<String>();
    long selectTime;

    @Override
    protected void setRoot() {
//        setTitleBar(R.color.colorBlue);
        setContentView(R.layout.activity_selectaddress);
    }

    @Override
    protected void setup() {

        setToolBar("选择发货地址", "");

    }


    @Override
    protected void init(@Nullable Bundle savedInstanceState) {
        rv.setLayoutManager(new LinearLayoutManager(SelectAddressAct.this));
        rv.setItemAnimator(new DefaultItemAnimator());
//        rv.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
        ptr.setLastUpdateTimeRelateObject(this);
        ptr.disableWhenHorizontalMove(true);
//        rv.setOnLoadMoreListener(new OnLoadMoreListener() {
//            @Override
//            public void loadMore() {
//            }
//        });
        ptr.setOnRefreshListener(new OnDefaultRefreshListener() {
            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
//                presenter.getList(true, sp.getString("id", "0"));
            }
        });
        getData();



    }


    @Override
    public void onNetErrorEvent(NetErrorEvent event) {
        super.onNetErrorEvent(event);
    }

    @Override
    protected void onNetError(NetErrorEvent event) {

    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    public void refreshComplete() {
        ptr.onRefreshComplete();
    }


    private void getData(){
        new LoginBiz().getAddress( new BaseBiz.Callback<SiteAddressBean>() {
            @Override
            public void onSuccess(SiteAddressBean integralTotalBean) {



                for (int i = 0;i<integralTotalBean.getSiteAddressList().length;i++)
                {
                    address.add(integralTotalBean.getSiteAddressList()[i]);
                }
                ptr.onRefreshComplete();
                if (adp == null) {
                    adp = new SiteAddressAdapter(SelectAddressAct.this, address,0);
                    rv.setAdapter(adp);
                } else {
                    adp.notifyDataSetChanged();
                }
                adp.setOnItemClickListener(new SuperBaseAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        EventBus.getDefault().post(new SiteAddressEvent(address.get(position)));
                        finish();
                    }
                });
            }

            @Override
            public void onFailure(SiteAddressBean integralTotalBean) {

            }
        });


    }


    private void setInfo() {
//        if (itemsBeans.size() == 0) {
//            showMsg("您暂时没有提现记录");
//            return;
//        }
//        if (adp == null) {
//            adp = new PresentRecordAdapter(GetJIFenRecordAct.this, beans);
//            rv.setAdapter(adp);
//        } else {
//            adp.getData().clear();
//            adp.setDatas(beans);
//            adp.notifyDataSetChanged();
//        }

    }

}
